package com.sharkburner.aeris.ui.module.article.component;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sharkburner.aeris.bean.MessageResource;
import com.sharkburner.aeris.dao.entity.Article;
import com.sharkburner.common.listener.GridViewListener;
import com.vaadin.terminal.ExternalResource;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.Link;
import com.vaadin.ui.VerticalLayout;

@Component
public class ArticleGridDetailView implements GridViewListener<Article> {

    @Autowired
    private transient MessageResource messageResource;

    @Override
    public AbstractComponent renderObject(Article article) {
	VerticalLayout articleCol = new VerticalLayout();
	articleCol.setWidth("50.0%");

	Link link = new Link();
	link.setCaption(article.getName());
	link.setResource(new ExternalResource(article.getLink()));
	link.setTargetName("_blank");
	articleCol.addComponent(link);

	Label description = new Label(article.getDescr());
	description.setWidth("500px");
	description.setContentMode(Label.CONTENT_XHTML);

	articleCol.addComponent(description);

	Label facebook = new Label(messageResource.getText("share.facebook",
		article.getLink()), Label.CONTENT_XHTML);

	articleCol.addComponent(facebook);

	return articleCol;
    }
}
